﻿Imports System.IO
Imports System.Text

Module ModHRDFile

    ' 获取版本
    Public Function GetVersion(ByVal Path As String)
        Dim hrdFile As StreamReader = New StreamReader(Path)
        Dim Txt As String = hrdFile.ReadLine
        Txt = hrdFile.ReadLine
        hrdFile.Close()
        Return Txt
    End Function

    ' 获取步数
    Public Function GetNumber(ByVal Path As String)
        Try
            Dim hrdFile As StreamReader = New StreamReader(Path)
            Dim Line2 As String = hrdFile.ReadLine
            Line2 = hrdFile.ReadLine
            Line2 = hrdFile.ReadLine
            hrdFile.Close()
            Return Line2
        Catch ex As Exception
            MsgBox(Path & "不是正常文件！")
        End Try
    End Function

    ' 存文件初始化棋盘
    Public Sub InitChessboard(ByVal Path As String)
        Try
            Dim hrdFile As StreamReader = New StreamReader(Path)
            Dim line As String = hrdFile.ReadLine

            Do While (line <> "HV")
                line = hrdFile.ReadLine
            Loop

            line = hrdFile.ReadLine
            If line = 1 Then
                Frmmain.Pic_Chessman_MC.Image = Global.华容道.My.Resources.MC_H
            Else
                Frmmain.Pic_Chessman_MC.Image = Global.华容道.My.Resources.MC_V
            End If
            line = hrdFile.ReadLine
            If line = 1 Then
                Frmmain.Pic_Chessman_ZY.Image = Global.华容道.My.Resources.ZY_H
            Else
                Frmmain.Pic_Chessman_ZY.Image = Global.华容道.My.Resources.ZY_V
            End If
            line = hrdFile.ReadLine
            If line = 1 Then
                Frmmain.Pic_Chessman_ZF.Image = Global.华容道.My.Resources.ZF_H
            Else
                Frmmain.Pic_Chessman_ZF.Image = Global.华容道.My.Resources.ZF_V
            End If
            line = hrdFile.ReadLine
            If line = 1 Then
                Frmmain.Pic_Chessman_HZ.Image = Global.华容道.My.Resources.HZ_H
            Else
                Frmmain.Pic_Chessman_HZ.Image = Global.华容道.My.Resources.HZ_V
            End If
            line = hrdFile.ReadLine
            If line = 1 Then
                Frmmain.Pic_Chessman_GY.Image = Global.华容道.My.Resources.GY_H
            Else
                Frmmain.Pic_Chessman_GY.Image = Global.华容道.My.Resources.GY_V
            End If

            Do While (line <> "Position")
                line = hrdFile.ReadLine
            Loop

            line = hrdFile.ReadLine
            Dim s() As String = Split(line, ",")
            Frmmain.Pic_Chessman_CC.Location = New Point(s(0), s(1))

            line = hrdFile.ReadLine
            s = Split(line, ",")
            Frmmain.Pic_Chessman_MC.Location = New Point(s(0), s(1))

            line = hrdFile.ReadLine
            s = Split(line, ",")
            Frmmain.Pic_Chessman_ZY.Location = New Point(s(0), s(1))

            line = hrdFile.ReadLine
            s = Split(line, ",")
            Frmmain.Pic_Chessman_ZF.Location = New Point(s(0), s(1))

            line = hrdFile.ReadLine
            s = Split(line, ",")
            Frmmain.Pic_Chessman_HZ.Location = New Point(s(0), s(1))

            line = hrdFile.ReadLine
            s = Split(line, ",")
            Frmmain.Pic_Chessman_GY.Location = New Point(s(0), s(1))

            line = hrdFile.ReadLine
            s = Split(line, ",")
            Frmmain.Pic_Chessman_Zu_1.Location = New Point(s(0), s(1))

            line = hrdFile.ReadLine
            s = Split(line, ",")
            Frmmain.Pic_Chessman_Zu_2.Location = New Point(s(0), s(1))

            line = hrdFile.ReadLine
            s = Split(line, ",")
            Frmmain.Pic_Chessman_Zu_3.Location = New Point(s(0), s(1))

            line = hrdFile.ReadLine
            s = Split(line, ",")
            Frmmain.Pic_Chessman_Zu_4.Location = New Point(s(0), s(1))

            line = hrdFile.ReadLine
            s = Split(line, ",")
            Frmmain.Pic_Chess_Choose_1.Location = New Point(s(0), s(1))

            line = hrdFile.ReadLine
            s = Split(line, ",")
            Frmmain.Pic_Chess_Choose_2.Location = New Point(s(0), s(1))
        Catch ex As Exception
            MsgBox(Path & "不是标准的HRD文件")
        End Try

    End Sub

End Module
